/**
 * 用户中心_用户维护_角色维护 前端数据模拟
 */

import Mock from 'mockjs';
import { param2Obj } from '@/utils';


// 角色查询list
const roleQueryList = [];
// list大小
const count = 100;

// 初始化用户查询list数据
for (let i = 0; i < count; i++) {
    roleQueryList.push(Mock.mock({
      id:'1111111111111111111',  
      name: '@increment',
      described: '@cname',
      isSuperAdmin: 1,
      function: ''
    }));
}


const roleMap = {
    role: {
        meta: {
            code: 200,
            message: ''
        },
        data: {}
    }
}


export default {
    getRole: config => {
        // 得到post的参数
        // const { page, pageSize, queryKey } = JSON.parse(config.body);
        const { page, pageSize, queryKey } = param2Obj(config.url);

        // 分页查询
        const pageList = roleQueryList.filter((item, index) => index < pageSize * page && index >= pageSize * (page - 1));

        return {
            meta: {
                code: 200,
                message: ''
            },
            data: {
                total: roleQueryList.length,
                items: pageList
            }
        }
    },
    addRole: () => {
        return roleMap['role'];
    },
    updateRole: () => {
        return roleMap['role'];
    },
    deleteRole: () => {
        return roleMap['role'];
    }
}